package inventory

import (
	"LogisticsPort/model"
	"LogisticsPort/sql"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

func inventoryStock(inventory *gin.RouterGroup) {
	//销售
	stock := inventory.Group("/stock")
	{
		stock.GET(sql.RequestList, inventoryList)
	}
}

func inventoryList(c *gin.Context) {
	sql.HttpHandle(sql.GET, c, func(db *gorm.DB) (*gorm.DB, interface{}) {
		var list []model.Inventory
		db.
			Select("inventory.*," +
				"product.product_name,product.factory_no,product.specification," +
				"purchase_product.container_no,purchase_product.contract_no").
			Joins("left join product on inventory.product_id = product.id").
			Joins("left join purchase_product on inventory.purchase_product_id = purchase_product.id").
			Find(&list)
		return db, list
	})
}
